<style lang="less" scoped>
.huiyi-project {
  width: 100%;
  height: 100%;
  /deep/.el-table__inner-wrapper {
    height: 100% !important;
  }
  .pagination-css {
    padding: 5px;
    box-sizing: border-box;
    background-color: #fff;
    display: flex;
    justify-content: right;
    margin-top: 5px;
  }
}
</style>

<template>
  <div class="huiyi-project">
    <el-form :model="ruleForm" inline class="form-css">
      <el-form-item label="机构名称：">
        <el-input
          v-model="ruleForm.insname"
          placeholder="请输入机构名称"
          style="width: 200px"
        ></el-input>
      </el-form-item>
      <el-form-item label="活动时间：">
        <el-date-picker
          v-model="ruleForm.activeTime"
          type="daterange"
          range-separator="-"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          value-format="YYYY-MM-DD"
          style="width: 200px"
        />
      </el-form-item>
      <el-form-item label="活动名称：">
        <el-input
          v-model="ruleForm.activeName"
          placeholder="请输入活动名称"
          style="width: 200px"
        ></el-input>
      </el-form-item>
      <el-form-item label="所在地区：">
        <el-input
          v-model="ruleForm.activeAddr"
          placeholder="请输入所在地区"
          style="width: 200px"
        ></el-input>
      </el-form-item>
      <el-form-item label="">
        <el-button type="primary" @click="search"
          ><el-icon style="margin-right: 6px"><Search /></el-icon>
          搜索</el-button
        >
        <el-button @click="reset"
          ><el-icon style="margin-right: 6px"><Refresh /></el-icon>
          重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-table
      v-loading="tableLoading"
      :data="tableData"
      :header-cell-style="{ backgroundColor: '#EEF6FF' }"
      stripe
      border
      height="calc(100% - 170px)"
      style="width: 100%; margin-top: 10px"
    >
      <el-table-column
        label="场次ID"
        align="center"
        prop="actionId"
      ></el-table-column>
      <!-- <el-table-column label="场次名称" align="center" prop="acitionName"></el-table-column> -->
      <el-table-column
        label="机构ID"
        align="center"
        prop="organId"
      ></el-table-column>
      <el-table-column
        label="机构名称"
        align="center"
        prop="organName"
      ></el-table-column>
      <el-table-column
        label="活动开始时间"
        align="center"
        prop="actionStartDate"
      ></el-table-column>
      <el-table-column
        label="活动结束时间"
        align="center"
        prop="actionEndDate"
      ></el-table-column>
      <el-table-column
        label="所在地区"
        align="center"
        prop="region"
      ></el-table-column>
      <el-table-column
        label="详细地址"
        align="center"
        prop="address"
      ></el-table-column>
      <el-table-column
        label="活动名称"
        align="center"
        prop="actionName"
      ></el-table-column>
      <el-table-column
        label="申请联系人"
        align="center"
        prop="contactPerson"
      ></el-table-column>
      <el-table-column
        label="联系方式"
        align="center"
        prop="contactTel"
      ></el-table-column>
      <el-table-column
        label="检查部位"
        align="center"
        prop="scanPosition"
      ></el-table-column>
    </el-table>
    <el-pagination
      v-model:current-page="pageList.current"
      v-model:page-size="pageList.size"
      :page-sizes="[20, 40, 60, 80]"
      small="small"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageList.total"
      class="pagination-css"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
import { getActionList } from "@/apis/sessionInfo";
import format from "@/utils/format";
export default {
  data() {
    return {
      ruleForm: {
        insname: "",
        activeTime: [],
        activeName: "",
        activeAddr: "",
      },
      tableLoading: false,
      tableData: [],
      pageList: {
        current: 1,
        size: 20,
        total: 0,
      },
    };
  },
  mounted() {
    this.init();
  },
  methods: {
    init() {
      this.pageList.current = 1;
      this.getTableData();
    },
    getTableData() {
      this.tableLoading = true;
      this.tableData = [];
      getActionList({
        uname: this.$store.getters.name,
        inscode: this.$store.getters.inscode,
        organName: this.ruleForm.insname,
        organName: this.ruleForm.insname,
        actionStartDate:
          this.ruleForm.activeTime.length > 0
            ? this.ruleForm.activeTime[0]
            : "",
        actionEndDate:
          this.ruleForm.activeTime.length > 0
            ? this.ruleForm.activeTime[1]
            : "",
        region: this.ruleForm.activeAddr,
        actionName: this.ruleForm.activeName,
        page: this.pageList.current,
        size: this.pageList.size,
      }).then((res) => {
        if (res.code == 0) {
          if (res.data && res.data.length > 0) {
            res.data.forEach((el) => {
              el.actionStartDate = format(
                el.actionStartDate * 1000,
                "YYYY-MM-DD"
              );
              el.actionEndDate = format(el.actionEndDate * 1000, "YYYY-MM-DD");
            });

            this.tableData = res.data;
          }
          this.pageList.total = res.size;
          this.tableLoading = false;
        }
      });
    },
    search() {
      this.pageList.current = 1;
      this.getTableData();
    },
    reset() {
      this.ruleForm.insname = "";
      this.ruleForm.activeTime = [];
      this.ruleForm.activeName = "";
      this.ruleForm.activeAddr = "";
      this.init();
    },
    handleSizeChange(val) {
      this.pageList.current = 1;
      this.pageList.size = val;
      this.getTableData();
    },
    handleCurrentChange(val) {
      this.pageList.current = val;
      this.getTableData();
    },
  },
};
</script>